package com.gxa.user.recycling.dao.impl;

import com.gxa.core.recycling.pojo.Goods;
import com.gxa.core.recycling.pojo.Goodsorder;
import com.gxa.user.recycling.dao.GoodsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

@Repository("/goodsDao")
public class GoodsDaoImpl implements GoodsDao {
    @Autowired
    MongoTemplate mongoTemplate;
    @Override
    public void insertOrUpdate(Goods goods) {
        Query query=Query.query(Criteria.where("id").is(goods.getId()));
        Update update=new Update();
        update.set("id",goods.getId());
        update.set("counts",goods.getCounts());
        update.set("hot",goods.getHot());
        update.set("name",goods.getName());
        update.set("needPoints",goods.getNeedPoints());
        update.set("rank",goods.getRank());
        update.set("state",goods.getState());
        update.set("type",goods.getType());
        update.set("remark",goods.getRemark());
        mongoTemplate.upsert(query,update,Goods.class);
    }
}
